package com.king.juc.n8.jucdemo.stamped;

import lombok.extern.slf4j.Slf4j;

/**
 * StampedLock 案例
 * 优点
 *  乐观读
 *
 * 缺点
 *  不支持条件变量
 *  不支持可重入
 * @author king
 * @date 2020/12/13 14:16
 */
@Slf4j(topic = "c.StampedLockTest")
public class StampedLockTest {
    public static void main(String[] args) {
        DataContainerStamped dataContainer = new DataContainerStamped(1);

        new Thread(() -> {
            dataContainer.read(1);
        }, "t1").start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

//        new Thread(() -> {
//            dataContainer.read(0);
//        }, "t2").start();

        new Thread(() -> {
            dataContainer.write(1000);
        }, "t2").start();
    }
}
